<?php

namespace App\Observers;

use App\Comment;
use Illuminate\Support\Facades\DB;

class CommentObserver {

	public function saved(Comment $comment) {
		if (!isset($comment->status) || $comment->status) {
			DB::table('items')->where('id', $comment->item_id)->increment('comment_nums');
		} else {
			DB::table('items')->where('id', $comment->item_id)->decrement('comment_nums');
		}
	}

	public function deleting(Comment $comment) {
		DB::table('items')->where('id', $comment->item_id)->decrement('comment_nums');
	}
}